var e = require, t = module, n = exports;

Object.defineProperty(n, "__esModule", {
    value: !0
});

var o = e("GameConfig"), i = e("GameData"), a = e("Global"), r = e("EggsManager"), s = e("PetManager"), c = e("UIManager"), l = function() {
    function e() {}
    return e.getInstance = function() {
        return this._manager || (this._manager = new e()), this._manager;
    }, e.prototype.getDraw = function(e) {
        return void 0 === e && (e = o.GC.drawConfig), i.GD.topRank < 42 && (e = e.filter(function(e) {
            return e.type != a.RewardType.ARM;
        })), s.default.getInstance().isHas(0) && (e = e.filter(function(e) {
            return e.type != a.RewardType.PET;
        })), s.default.getInstance().isHas(1) && (e = e.filter(function(e) {
            return e.type != a.RewardType.DRAGON;
        })), (e = -1 < i.GD.skins.indexOf(22) ? e.filter(function(e) {
            return e.type != a.RewardType.SKIN;
        }) : e)[this.getDraw2(e)];
    }, e.prototype.getDraw2 = function(a) {
        void 0 === a && (a = o.GC.drawConfig);
        var e = 0, t = [];
        a.forEach(function(a) {
            return e += a.weight;
        }), a.forEach(function(a) {
            0 < t.length ? t.push(t[t.length - 1] + a.weight / e) : t.push(a.weight / e);
        });
        for (var d = Math.random(), n = 0; n < t.length - 1 && t[n] < d; ) n++;
        return n;
    }, e.prototype.doDraw = function(e) {
        void 0 === e && (e = this.getDraw());
        var t = Object.assign({}, e);
        switch (t.data || (t.data = {}), t.type) {
          case a.RewardType.DIAMOND:
            null != t.data.num && !isNaN(t.data.num) || (t.data.num = 500), i.GD.updateNumber("diamond", t.data.num);
            break;

          case a.RewardType.MONEY:
            null != t.data.num && !isNaN(t.data.num) || (t.data.num = 500), i.GD.updateNumber("money", t.data.num);
            break;

          case a.RewardType.SKIN:
            null != t.data.idx && !isNaN(t.data.idx) || (t.data.idx = 15), t.data.time && -1 < t.data.time ? i.GD.skins.indexOf(t.data.idx) < 0 && o.GC.personExpectList.indexOf(t.data.idx) < 0 ? (a.G.tryPersonIdx = t.data.idx, 
            a.G.tryPersonMap.set(a.G.tryPersonIdx, {
                id: a.G.tryPersonIdx,
                time: Date.now() + 6e4 * t.data.time
            }), -1 < i.GD.skins.indexOf(i.GD.personIdx) && (i.GD.lastPersonIdx = i.GD.personIdx), 
            i.GD.personIdx = t.data.idx, cc.systemEvent.emit("refresh_tryTime")) : (t.type = a.RewardType.DIAMOND, 
            t.data.num = 500, i.GD.updateNumber("diamond", t.data.num)) : i.GD.hasSkin(t.data.idx) ? (t.type = a.RewardType.DIAMOND, 
            t.data.num = 500, i.GD.updateNumber("diamond", t.data.num)) : (i.GD.addSkin(t.data.idx), 
            i.GD.personIdx = t.data.idx);
            break;

          case a.RewardType.PET:
            t.data.idx = 0, s.default.getInstance().isHas(0) ? (t.type = a.RewardType.PIECE, 
            t.data.num = 300, i.GD.updateNumber("piece", t.data.num)) : (s.default.getInstance().getRealData(0).has = 1, 
            i.GD.petDataIdx = 0);
            break;

          case a.RewardType.ARM:
            null != t.data.idx && !isNaN(t.data.idx) || (t.data.idx = a.G.drawGunModelList[0].id + 2e3), 
            t.data.idx < 2e3 && 1e3 <= t.data.idx && t.data.time && ((n = new a.EggData(t.data.idx - 1e3)).time = t.data.time + Date.now(), 
            r.default.getInstance().setDataGun(t.data.idx - 1e3, n)), 3e3 <= t.data.idx && (i.GD.gunOwnList.includes(t.data.idx) ? (t.data.num = 300, 
            i.GD.updateNumber("piece", t.data.num), c.default.getInstance().showToast({
                piece: 300
            })) : i.GD.gunOwnList.push(t.data.idx));
            var d = c.default.getInstance().getPnl("start"), n = d.boxs.filter(function(a) {
                return a.isEmpty();
            });
            0 < n.length ? (d.appendItem(t.data.idx, n[0]), d.updateMatrix()) : d.appendEquip(t.data.idx), 
            2001 == t.data.idx && 3 != i.GD.personIdx && 9 != i.GD.personIdx || (i.GD.gunIdx = t.data.idx), 
            1008 == t.data.idx && -17 != i.GD.personIdx || (i.GD.gunIdx = t.data.idx);
            break;

          case a.RewardType.PIECE:
            null != t.data.num && !isNaN(t.data.num) || (t.data.num = 500), i.GD.updateNumber("piece", t.data.num);
            break;

          case a.RewardType.DRAGON:
            t.data.idx = 100, s.default.getInstance().isHas(1) ? (t.type = a.RewardType.PIECE, 
            t.data.num = 300, i.GD.updateNumber("piece", t.data.num)) : (s.default.getInstance().getRealData(1).has = 1, 
            cc.systemEvent.emit("hatch_reward", !1));
            break;

          case a.RewardType.ELF:
            t.data.idx = 200, s.default.getInstance().isHas(2) ? (t.type = a.RewardType.PIECE, 
            t.data.num = 300, i.GD.updateNumber("piece", t.data.num)) : (s.default.getInstance().getRealData(2).has = 1, 
            i.GD.petDataIdx = 2);
            break;

          case a.RewardType.STONE:
            null != t.data.num && !isNaN(t.data.num) || (t.data.num = 500), i.GD.updateNumber("stone", t.data.num);
            break;

          case a.RewardType.ANGLE:
            t.data.idx = 300, s.default.getInstance().isHas(3) ? (t.type = a.RewardType.PIECE, 
            t.data.num = 300, i.GD.updateNumber("piece", t.data.num)) : (s.default.getInstance().getRealData(3).has = 1, 
            i.GD.petDataIdx = 3);
        }
        return {
            type: t.type,
            num: t.data && !isNaN(t.data.num) ? t.data.num : null,
            idx: t.data && !isNaN(t.data.idx) ? t.data.idx : null
        };
    }, e._manager = null, e;
}();

n.default = l;